package cc.lishixi.book.service;

import cc.lishixi.book.dao.mapper.ParameterRowMapper;
import cc.lishixi.book.entity.Parameter;
import cc.lishixi.book.service.api.AbstractService;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by LiShixi on 2016/7/24 0024.
 * http://www.lishixi.cc
 */
@Component
public class ParameterService extends AbstractService<Parameter> {
    @Override
    public List<Parameter> list() {
        return jdbcTemplate.query("select * from parameter", new ParameterRowMapper());
    }

    @Override
    public boolean delete(Integer id) {
        return jdbcTemplate.update("delete from parameter where id=?", id) > 0;
    }

    @Override
    public boolean edit(Parameter p) {
        String sql = "UPDATE `book`.`parameter` SET `type`=?, `amount`=?, `period`=?, `dailyfine`=? WHERE  `id`=?;";
        return jdbcTemplate.update(sql, p.getType(), p.getAmount(), p.getPeriod(), p.getDailyfine(), p.getId()) > 0;
    }

    @Override
    public boolean add(Parameter p) {
        String sql = "INSERT INTO `book`.`parameter` (`type`, `amount`, `period`, `dailyfine`) VALUES (?, ?, ?, ?);";
        return jdbcTemplate.update(sql, p.getType(), p.getAmount(), p.getPeriod(), p.getDailyfine()) > 0;
    }
}
